<?php

$api = app('Dingo\Api\Routing\Router');

$params = [
    'middleware' => [
        'api.throttle',
        'bindings',
        'serializer:array',
    ],
    'limit'      => 60,
    'expires'    => 1,
];

$api->version('v1', $params, function($api) {
    //首页数据
    $api->get('index', [\App\Http\Controllers\Api\IndexController::class, 'index']);
    //商品详情
    $api->get('goods/{id}', [\App\Http\Controllers\Api\GoodsController::class, 'show']);
    //商品列表
    $api->get('goods', [\App\Http\Controllers\Api\GoodsController::class, 'index']);

    //需要登录的路由
    $api->group(['middleware' => 'api.auth'], function($api) {
        /**
         * 个人中心
         */
        //用户详情
        $api->get('user', [\App\Http\Controllers\Api\UserController::class, 'userInfo']);
        //更新用户信息
        $api->put('user', [\App\Http\Controllers\Api\UserController::class, 'updateUserInfo']);
        //更新头像
        $api->patch('user/avatar', [\App\Http\Controllers\Api\UserController::class, 'updateAvatar']);

        /**
         * 购物车
         */
        //购物车的资源路由
        $api->resource('carts', \App\Http\Controllers\Api\CartController::class, [
            'except' => ['show'],
        ]);

        /**
         * 订单
         */
        //订单预览页
        $api->get('orders/preview', [\App\Http\Controllers\Api\OrderController::class, 'preview']);
        //订单提交
        $api->post('orders', [\App\Http\Controllers\Api\OrderController::class, 'store']);
    });
});

